using System.Diagnostics;
using System.Drawing;

namespace TouchSmart.Animations
{
    public abstract class TwoDimensionsAnimation : Animation
    {
        protected float _xVelocity = 2.0f;
        protected float _yVelocity = 2.0f;

        private int _xCumulativeMovement;
        private int _yCumulativeMovement;

        protected TwoDimensionsAnimation(float xVelocity, float yVelocity)
        {
            _xVelocity = xVelocity;
            _yVelocity = yVelocity;
        }

        protected abstract float GetXMovement(int delta);
        protected abstract float GetYMovement(int delta);

        protected override void AnimateInternal(int delta)
        {
            Debug.WriteLine("Animation delta: " + delta);

            var xMovement = GetXMovement(delta);
            var yMovement = GetYMovement(delta);

            foreach (var widget in _widgets)
            {
                widget.Location = new Point(widget.Location.X + (int)xMovement, widget.Location.Y + (int)yMovement);
            }

            this._xCumulativeMovement += (int)xMovement;
            this._yCumulativeMovement += (int)yMovement;
        }

        protected override bool GetIsCompleted()
        {
            return this._xCumulativeMovement > 100 || this._yCumulativeMovement > 100;
        }

        protected override void Reset()
        {
            this._xCumulativeMovement = 0;
            this._yCumulativeMovement = 0;
        }
    }
}